package org.domeos.framework.engine.coderepo;

import org.domeos.exception.RSAKeypairException;
import org.domeos.framework.api.biz.project.ProjectBiz;
import org.domeos.framework.api.consolemodel.project.CodeSourceInfo;
import org.domeos.framework.api.model.ci.BuildHistory;
import org.domeos.framework.api.model.ci.related.CommitInformation;
import org.domeos.framework.api.model.global.Server;
import org.domeos.framework.api.model.project.Project;
import org.domeos.framework.api.model.project.related.CodeConfiguration;
import org.domeos.framework.api.model.project.related.UserDefinedDockerFile;
import org.domeos.framework.engine.exception.DaoException;

import java.util.List;

/**
 * Created by feiliu206363 on 2015/12/10.
 */
public interface CodeApi {
    /**
     *
     * @param userId user id in domeos
     * @return
     */
    List<CodeSourceInfo> listCodeInfo(int userId);

    /**
     *
     * @return
     */
    List<CodeSourceInfo.ProjectInfo> getGitlabProjectInfos();

    /**
     *
     * @param svnId
     * @return
     */
    CodeSourceInfo.ProjectInfo getSubversionProjectInfo(int svnId);

    /**
     *
     * @param projectId project id in code repo
     * @param title
     * @param key
     * @return
     */
    int setDeployKey(int projectId, String title, String key);

    /**
     *
     * @param projectId
     * @param path
     * @return
     */
    CommitInformation getCommitInfo(int projectId, String path);

    /**
     *
     * @param projectId project id in code repo
     * @param branch
     * @return
     */
    CommitInformation getBranchCommitInfo(int projectId, String branch);

    /**
     *
     * @param projectId
     * @param tag
     * @return
     */
    CommitInformation getTagCommitInfo(int projectId, String tag);

    /**
     *
     * @param projectId
     * @param deployKeyId
     * @return
     */
    boolean checkDeployKey(int projectId, int deployKeyId);

    /**
     *
     * @param projectId
     * @param branch
     * @return
     */
    String getReadme(int projectId, String branch);

    /**
     *
     * @param projectId
     * @return
     */
    List<String> getBranches(int projectId);

    /**
     *
     * @param projectId
     * @param ref
     * @param fileName
     * @return
     */
    String getDockerFile(int projectId, String ref, String fileName);

    /**
     * when check project in code repository fail, delete deploy keys named DomeOS first
     * @param projectId
     */
    void deleteDeployKeys(int projectId);

    /**
     *
     * @param codeId
     * @return
     */
    List<String> getTags(int codeId);

    void applyProjectHook(Server gitServer, Project project);

    String fetchPrivateKey(ProjectBiz projectBiz, Project project, CodeConfiguration codeConfig) throws RSAKeypairException, DaoException;

    String obtainBuildPath(UserDefinedDockerFile dockerFileInfo, BuildHistory buildInfo, Project project, String ref);

    String obtainDockerFilePath(UserDefinedDockerFile dockerFileInfo, BuildHistory buildInfo, Project project, String ref);
}
